package org.springblade.modules.admin.vo;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.modules.admin.enums.ElevatorMaintainStatusEnums;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.entity.User;

import java.util.Date;
import java.util.List;

/**
 * @Date 9:54 2023/2/10
 * @Description {
 * 电梯责任关联分页
 * }
 * @Author lsay
 **/
@Data
public class ElevatorPrincipalPageVO {

	@JsonSerialize(using = ToStringSerializer.class)
	private Long elevatorId;

	@JsonSerialize(using = ToStringSerializer.class)
	private Long buildingId;

	private String buildingName;

	private String buildingAddress;

	private String elevatorAddress;

	private Integer useType;

	private Integer maintainStatus;

	private Integer elevatorStop;

	private String elevatorNum;

	private String privateNum;

	@JsonSerialize(using = ToStringSerializer.class)
	private Long principalDeptId;

	/**
	 * 部门所有祖级
	 */
	private String ancestors;

	/**
	 * 机构类型
	 */
	private Integer deptCategory;

	private String principalDeptName;

	private String principalUserNames;
	private String principalUserIds;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date updateTime;

	@ApiModelProperty(value = "祖级机构集合")
	private List<Dept> ancestorsDept;

	private List<User> userList;

	/**
	 * 上一次维保签字日期
	 */
	@JsonFormat(pattern = "yyyy-MM-dd")
	private Date previousPlanDate;

	/**
	 * 下一次保养计划日期
	 */
	@JsonFormat(pattern = "yyyy-MM-dd")
	private Date nextPlanDate;

	/**
	 * 逾期临界日期
	 */
	@JsonFormat(pattern = "yyyy-MM-dd")
	private Date overdueDate;

	/**
	 * 年审梯合规状态描述
	 */
	private String overdueDateDesc;

	/**
	 * 在保情况
	 */
	private String maintainStatusDesc;

	private String maintainStatusName;

	private String eleMaintainStatusDesc;

	private Integer fromType;

	private String buildingUserName;

	private String buildingUserNameExt;

	private String registerNumber;

	private String brandName;

	private Integer buildingType;


	public void setMaintainStatus(Integer maintainStatus) {
		this.maintainStatus = maintainStatus;
		if (ObjectUtil.isNotEmpty(maintainStatus)) {
			if (maintainStatus == -1) {
				this.maintainStatusDesc = "--";
				this.eleMaintainStatusDesc = "其它--";
			} else {
				this.maintainStatusDesc = ElevatorMaintainStatusEnums.getName(maintainStatus);
				if (maintainStatus == ElevatorMaintainStatusEnums.OUT_TIME_STOP.getId() || maintainStatus == ElevatorMaintainStatusEnums.OUT_TIME_END_HAS_NEXT.getId() || maintainStatus == ElevatorMaintainStatusEnums.OUT_TIME_END.getId()) {
					this.eleMaintainStatusDesc = "脱保";
				} else if (maintainStatus == ElevatorMaintainStatusEnums.RELEASE_INSURANCE.getId()) {
					this.eleMaintainStatusDesc = "丢保";
				} else if (maintainStatus == ElevatorMaintainStatusEnums.CONTRACT_IN_TIME.getId()) {
					this.eleMaintainStatusDesc = "在保";
				} else if (maintainStatus == ElevatorMaintainStatusEnums.DIS_ENABLE.getId()) {
					this.eleMaintainStatusDesc = "非在保";
				}
			}
			this.maintainStatusName = ElevatorMaintainStatusEnums.getName(maintainStatus);
		}

	}

	public void setOverdueDate(Date overdueDate) {
		this.overdueDate = overdueDate;
		if (ObjectUtil.isNotEmpty(overdueDate)) {
			Date now = DateUtil.parseDate(DateUtil.today());
			if (overdueDate.getTime() == now.getTime()) {
				this.overdueDateDesc = "明天即将违规";
			} else if (overdueDate.getTime() > now.getTime()) {
				this.overdueDateDesc = "正常";
			} else {
				long betweenDay = DateUtil.between(overdueDate, now, DateUnit.DAY);
				this.overdueDateDesc = "已违规（" + betweenDay + "）天";
			}
		}
	}
}
